function [ assign_mat, p] = auction2(w)

[rows, cols] = size(w);
if rows>cols
    w = w';
    flip_flag=1;
else
    flip_flag=0;
end

[no_bidders, no_goods] = size(w);

assign_mat = zeros(no_bidders,no_goods);

unassigned = ones(1,no_bidders);

p = zeros(1,no_goods);                      % initialise price for each item
won = zeros(1,no_bidders)*NaN;
%e = 1/(no_goods+1);

%goods_left_flag = 1;
while (any(unassigned==1))
    i = find(unassigned>0,1);              % take first non-committed bidder
    diff_vec  = w(i,:)-p;
    [best, ind] = max(diff_vec);
    diff_vec(ind) = [];
    [sec_best, ~] = max(diff_vec);
    if ~isempty(sec_best)
        p(ind)    = p(ind) + (best-sec_best);
    end
    % check if track steals obs from another track, if so mark other track as
    % unassigned
    if any(won==ind)
        bidder_ind                 = find(won==ind,1);
        unassigned(bidder_ind)     = 1;
        assign_mat(bidder_ind,ind) = 0;
        won(bidder_ind)            = NaN;
    end
    if best>0
        won(i)             = ind;
        assign_mat(i,ind)  = 1;
    end
    unassigned(i) = 0; % Use this to indicate that algorithm should not consider
                       % this bidder in next round if best score is zero 
                       % (no association can be made)
    %sum(unassigned)
end
    
if flip_flag==1
    assign_mat = assign_mat';
end